package com.weslide.weslideapp.parser;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.util.Log;

import com.weslide.weslideapp.pojo.ao.GiftAO;
import com.weslide.weslideapp.pojo.ao.GiftListAO;

public class GetGiftsParser {
	private GiftListAO giftListAO = new GiftListAO();

	public void parser(String jsonstring) throws JSONException {
		JSONArray jsonArray = new JSONArray(jsonstring);
		JSONObject statusJsonObject = jsonArray.getJSONObject(0);
		giftListAO.setStatus(statusJsonObject.getString("status"));
		if ("1".equals(giftListAO.getStatus())) {
			for (int i = 1; i < jsonArray.length(); i++) {
				GiftAO giftAO = new GiftAO();
				JSONObject dataJsonObject = jsonArray.getJSONObject(i);
				giftAO.setGoodId(dataJsonObject.getString("good_id"));
				giftAO.setName(dataJsonObject.getString("name"));
				giftAO.setNeedScore(dataJsonObject.getString("need_score"));
				giftAO.setMoney(dataJsonObject.getString("money"));
				giftAO.setShopTypeId(dataJsonObject.getString("shoptype_id"));
				giftAO.setShopTypeName(dataJsonObject
						.getString("shoptype_name"));
				giftAO.setTcount(dataJsonObject.getString("tcount"));
				giftAO.setOcount(dataJsonObject.getString("ocount"));
				giftAO.setImgUrl(dataJsonObject.getString("imgurls"));
				giftListAO.addGift(giftAO);
			}
		}
	}

	public GiftListAO getData() {
		return giftListAO;
	}
}
